package com.qeegoo.b2bautozityp.moudle.good.viewmodel;

import android.databinding.ObservableField;
import android.text.TextUtils;

import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.moudle.goods.model.GoodsDetailResult;

import java.util.Map;

import base.lib.util.ToastUtils;

/**
 * 王少岩 在 2017/10/9 创建了它
 */

public class GoodsPriceViewModel {
    public ObservableField<Integer> invoicePic = new ObservableField<>(R.mipmap.ic_switch_close);//是否提供发票
    public ObservableField<String> unitPrice = new ObservableField<>("");
    public ObservableField<String> tradePrice = new ObservableField<>("");
    public ObservableField<String> settlePrice = new ObservableField<>("");

    public void setPrice(GoodsDetailResult goodsDetailResult) {
        invoicePic.set(goodsDetailResult.goods.invoiceTag.equals("0") ? R.mipmap.ic_switch_close : R.mipmap.ic_switch_open);
        unitPrice.set(goodsDetailResult.goods.invoiceTag.equals("0") ? goodsDetailResult.goods.unitPriceNoInvoice : goodsDetailResult.goods.unitPrice);
        tradePrice.set(goodsDetailResult.goods.invoiceTag.equals("0") ? goodsDetailResult.goods.tradePriceNoInvoice : goodsDetailResult.goods.tradePrice);
        settlePrice.set(goodsDetailResult.goods.invoiceTag.equals("0") ? goodsDetailResult.goods.settlePriceNoInvoice : goodsDetailResult.goods.settlePrice);
    }

    public Map<String, String> getPriceInfoParam(Map<String, String> map) {
        if (TextUtils.isEmpty(unitPrice.get())){
            ToastUtils.showToast("请输入零售价");
            map.clear();
            return map;
        }
        if (TextUtils.isEmpty(settlePrice.get())){
            ToastUtils.showToast("请输入批发价");
            map.clear();
            return map;
        }
        if (TextUtils.isEmpty(tradePrice.get())){
            ToastUtils.showToast("请输入结算价");
            map.clear();
            return map;
        }
        map.put("invoiceTag", invoicePic.get() == R.mipmap.ic_switch_close ? "0" : "1");
        map.put("unitPriceNoInvoice", invoicePic.get() == R.mipmap.ic_switch_close ? unitPrice.get() : "");
        map.put("settlePriceNoInvoice", invoicePic.get() == R.mipmap.ic_switch_close ? settlePrice.get() : "");
        map.put("tradePriceNoInvoice", invoicePic.get() == R.mipmap.ic_switch_close ? tradePrice.get() : "");
        map.put("unitPrice", invoicePic.get() == R.mipmap.ic_switch_close ? "" : unitPrice.get());
        map.put("settlePrice", invoicePic.get() == R.mipmap.ic_switch_close ? "" : settlePrice.get());
        map.put("tradePrice", invoicePic.get() == R.mipmap.ic_switch_close ? "" : tradePrice.get());
        return map;
    }
}
